package com.vitria.m3oui.test.px;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class FileHelper {
	private static Log log_ = LogFactory.getLog(FileHelper.class);

	public static boolean writeToFile(String fname, String content){
		try {
		      File f = new File(fname);
		      if (f.exists()) {
		    	  log_.debug("File "+fname+" already exist.");
		      } else {
		    	  log_.debug("Create file "+ fname);
		    	  if (f.createNewFile()) {
		    		  log_.debug("File created successfully");
		    	  } else {
		    		  log_.error("File create fail!");
		    		  return false;
		    	  }
		     }
		     BufferedWriter output = new BufferedWriter(new FileWriter(f));
		     output.write(content);
		     output.close();
		}catch (Exception e) {
		     e.printStackTrace();
		     return false;
		}
		return true;
	}
}
